from transfer import sendPeakTimeToUnity

import numpy as np
import random
from os import abort

# 多个人的数据
# @param  n       人数
# @param  during  一个动作持续时间上限 (实际会在上限的一半和上限之间随机)
# @param  T       动作周期
# @param  repeat  重复次数
# @return
def generateMultiPersonUnityData(n = 4, during = 2, T = 2.2, repeat = 5):
    
    l = [0 for i in range(n)]
    for i in range(n):
        scale = random.random() * 0.5 + 0.5  # 随机生成一个动作的时长
        print(scale * during)
        l[i] = generateOnePersonData(scale * during, T, repeat)
    
    for row in range(8 * repeat):
        for personId in range(n):
            data = [l[personId][row], personId, row % 8]
            sendPeakTimeToUnity(data)


# 生成一个人的数据
# @param  during  一个动作的持续时间
# @param  T       动作周期
# @param  repeat  重复次数
# @return  返回 一个 8*repeat 的numpy array
def generateOnePersonData(during, T, repeat):
    if during >= T:
        print("动作时长大于周期")
        abort()
    
    action = [2460,2504,2547,2584,2615,2649,2683,2721]  # 从真实数据中提取出的一次动作的帧序列
    action = np.array(action)

    action = action - action[0]
    action = action / action[-1]  # 归一
    action = action * during
    actions = np.arange(8 * repeat, dtype=float)
    for i in range(repeat):
        for j in range(8):
            actions[i * 8 + j] = action[j] + i * T
    
    return actions
